<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperPackage}.CommonMapper">
    ${r'
    <sql id="dynamic_where_sort_limit">
        <if test="dynamicParams != null">
            <if test="dynamicParams.wheres != null and !dynamicParams.wheres.isEmpty()">
                <where>
                    <foreach collection="dynamicParams.wheres" item="whereItem">
                        AND ${whereItem.column} <![CDATA[ ${whereItem.operator} ]]>
                        <choose>
                            <when test="whereItem.operator == '}'in'${r' or whereItem.operator == '}'not in'${r'">
                                <foreach close=")" collection="whereItem.value" item="inItem" open="(" separator=",">
                                    #{inItem}
                                </foreach>
                            </when>
                            <otherwise>
                                #{whereItem.value}
                            </otherwise>
                        </choose>
                    </foreach>
                </where>
            </if>
            <if test="dynamicParams.sorts != null and !dynamicParams.sorts.isEmpty()">
                ORDER BY
                <foreach collection="dynamicParams.sorts" item="s" separator=",">
                    ${s}
                </foreach>
            </if>
            <if test="dynamicParams.limit != null and dynamicParams.limit > 0">
                limit #{dynamicParams.limit}
            </if>
        </if>
    </sql>
    <sql id="dynamic_where_sort">
        <if test="dynamicParams != null">
            <if test="dynamicParams.wheres != null and !dynamicParams.wheres.isEmpty()">
                <where>
                    <foreach collection="dynamicParams.wheres" item="whereItem">
                        AND ${whereItem.column} <![CDATA[ ${whereItem.operator} ]]>
                        <choose>
                            <when test="whereItem.operator == '}'in'${r' or whereItem.operator == '}'not in'${r'">
                                <foreach close=")" collection="whereItem.value" item="inItem" open="(" separator=",">
                                    #{inItem}
                                </foreach>
                            </when>
                            <otherwise>
                                #{whereItem.value}
                            </otherwise>
                        </choose>
                    </foreach>
                </where>
            </if>
            <if test="dynamicParams.sorts != null and !dynamicParams.sorts.isEmpty()">
                ORDER BY
                <foreach collection="dynamicParams.sorts" item="s" separator=",">
                    ${s}
                </foreach>
            </if>
        </if>
    </sql>
    <sql id="dynamic_where">
        <if test="dynamicParams != null">
            <if test="dynamicParams.wheres != null and !dynamicParams.wheres.isEmpty()">
                <where>
                    <foreach collection="dynamicParams.wheres" item="whereItem">
                        AND ${whereItem.column} <![CDATA[ ${whereItem.operator} ]]>
                        <choose>
                            <when test="whereItem.operator == '}'in'${r' or whereItem.operator == '}'not in'${r'">
                                <foreach close=")" collection="whereItem.value" item="inItem" open="(" separator=",">
                                    #{inItem}
                                </foreach>
                            </when>
                            <otherwise>
                                #{whereItem.value}
                            </otherwise>
                        </choose>
                    </foreach>
                </where>
            </if>
        </if>
    </sql>
   '}
</mapper>